import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
export default async function a002(fd: IFeidaoAiBrowserComponent) {

	const productid = get(fd, 'productid');
	const role_name = fd.data.node.querySelector<HTMLInputElement>('[name="role_name"]').value;
	const role_type_id = fd.data.node.querySelector<HTMLSelectElement>('[name="role_type_id"]').value;
	const icon = fd.data.node.querySelector<HTMLInputElement>('[name="icon"]').value;
	if (!role_name) {
		error('角色名称不能为空');

		return;
	}
	if (!role_type_id) {
		error('请选择角色类型');
		return;
	}
	const query = {
		role_name,
		productid,
		role_type_id,
		create_time: new Date().getTime(),
		icon
	};
	show_loading();
	const res = await nodejs('roler/zj-000002/s002', query);
	hide_loading();
	if (res === 'success') {
		fire('zj-000001', 'ec-002');
		fire('zj-000002', 'eu-001');
		success('保存成功');
	} else if (res === 'fail') {
		error('保存失败');
		return;
	} else {
		error('角色名称重复，无法保存');
		return;
	}
}
